/*
 * glMatrix.h
 *
 *  Created on: 30.10.2012
 *      Author: Martin
 */

#pragma once

#ifdef _WIN32 
#include <windows.h> 
#endif

#include "GL/gl.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "../engine/engineSettings.h"

namespace DataTypes
{
class Cube;
}

namespace World
{

class World
{
public:
	World(); // size of screen
	virtual ~World();

	glm::mat4 getProjection();
	glm::mat4 getView();
	void setView(glm::mat4 v); // set view matrix
	void ViewIdentity(); // view matrix * m(1)
	void setLightning(); // setup lightning
	void setLightPos(glm::vec3 pos); // setting light position
	void setProjection(glm::mat4 proj); // set projection matrix

	// shadows
	void setShadowProjection();

	void set2DProjection();

	// set view from light to point
	void setShadowView(glm::vec3 lookToPoint);

	// extracting frustum from scene settings
	void extractFrustum();
	bool PointInFrustum(glm::vec3 X);
	bool CubeInFrustum(DataTypes::Cube cube);

	void update();

	// X position of centre of sphere
	// radius
	float SphereInFrustum(glm::vec3 X, float radius);

	void drawLight();

	glm::mat4 getShadowProjection();
	glm::mat4 getShadowView();
	glm::mat4 getBiasMVP();

	glm::vec3 getLightPos();
	glm::vec3 getLightDif();
	glm::vec3 getLightAmb();
	glm::vec3 getLightSpe();
	float getLightPower();

	glm::mat4 get2DProjection();

private:
	float frustum[6][4];
	glm::mat4 Projection;
	glm::mat4 View;

	// for 2D
	glm::mat4 twoDProjection;

	//for shadows
	glm::mat4 shadowProjection;
	glm::mat4 shadowView;
	glm::mat4 biasMatrix;

	//DataTypes::Cube *lightCube;

	//setup light
	//diffuse light color variables
	glm::vec3 dLight;
	//ambient light color variables
	glm::vec3 aLight;
	glm::vec3 sLight;
	float lightPower;

	glm::vec3 ShadowlookToPoint;

	//light position variables
	glm::vec3 posLight;
};

// static declaration of world

// pointer to world object
extern World *world;

// utility for global counting
extern int counter;

// utility for global counting of boxes
extern int countBoxes;
extern int countBoxesVisible;

// NEED TO BE CALLED FIRST
// create world object and setup pointer
void worldInit();

// delete world object
void deleteWorld();
}

